package com.lagou.edu.service.impl;

import com.lagou.edu.dao.ResumeRepository;
import com.lagou.edu.entity.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ResumeServiceImpl implements ResumeService {

    private final ResumeRepository resumeRepository;

    public ResumeServiceImpl(ResumeRepository resumeRepository) {
        this.resumeRepository = resumeRepository;
    }

    @Override
    public List<Resume> findAll() {
        return resumeRepository.findAll();
    }

    @Override
    public Resume findById(Long id) {
        return resumeRepository.findById(id).orElseThrow(() -> new RuntimeException(String.format("简历ID[%d]无效", id)));
    }

    @Override
    @Transactional
    public void save(Resume resume) {
        resumeRepository.save(resume);
    }

    @Override
    public void delete(Long id) {
        resumeRepository.deleteById(id);
    }
}
